﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using XNADota.Input;

namespace XNADota.Camera
{
    class ArcBallCamera : BaseCamera
    {
        // constructor
        public ArcBallCamera(Game game) : base(game)
        {
            //forward = Vector3.Subtract(ArcBallCamera.S_LOOK_AT, cameraPosition);
            //length = forward.Length();
            //forward.Normalize();
        }

        // controller speed
        //private float moveSpeed = 1.0f;
        //private float rotationSpeed = 0.3f;
        //private float rollSpeed = 0.01f;

        // controllable
        private KeyboardState lastKeyBoardState = Keyboard.GetState();
        private MouseState lastMouseState = Mouse.GetState();
        private Vector3 RotatioVector3 = new Vector3(0, 0, 0);

        //public Vector3 Right
        //{
        //    get { return Vector3.Cross(_Forward, _Up); }
        //}

        //public Vector3 LookAt
        //{
        //    get { return _Position + _Forward * _Length; }
        //}

        public void ProcessInput(InputState inputState)
        {
            //Vector3 lookAt = LookAt;

            //float time = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //if (keyBoardState.IsKeyDown(Keys.A))
            //    lookAt += -Vector3.Multiply(Right, time * moveSpeed);
            //if (keyBoardState.IsKeyDown(Keys.D))
            //    lookAt += Vector3.Multiply(Right, time * moveSpeed);
            //if (keyBoardState.IsKeyDown(Keys.W))
            //    lookAt += Vector3.Multiply(_Forward, time * moveSpeed);
            //if (keyBoardState.IsKeyDown(Keys.S))
            //    lookAt += Vector3.Multiply(_Forward, -time * moveSpeed);


            //float xOffset = mouseState.X - lastMouseState.X;
            //float yOffset = mouseState.Y - lastMouseState.Y;

            //ButtonState leftButton = mouseState.LeftButton;
            //ButtonState rightButton = mouseState.RightButton;
            //if (mouseState.LeftButton == ButtonState.Pressed)
            //{
            //    lookAt += Vector3.Multiply(_Up, time * moveSpeed * yOffset);
            //}

            //if (mouseState.RightButton == ButtonState.Pressed)
            //{
            //    float fYawDelta = MathHelper.ToRadians(xOffset * rotationSpeed);
            //    float fRollDelta = MathHelper.ToRadians(yOffset * rotationSpeed);

            //    mYawAngle += -fYawDelta;
            //    mRollAngle += fRollDelta;

            //    Matrix cameraRot = Matrix.CreateFromYawPitchRoll(mYawAngle, 0, mRollAngle);

            //    forward = (ArcBallCamera.S_LOOK_AT - ArcBallCamera.S_CAMERA_POSITION);
            //    forward.Normalize();
            //    forward = Vector3.Transform(forward, cameraRot);
            //    up = Vector3.Transform(ArcBallCamera.S_UP, cameraRot);
            //}

            //int deltaScrollWheelValue = mouseState.ScrollWheelValue - lastMouseState.ScrollWheelValue;
            //if (deltaScrollWheelValue != 0 )
            //{

            //    forward.Normalize();
            //    length += -(float)deltaScrollWheelValue * rollSpeed;
            //    length = Math.Max(3, length);
            //}

            //cameraPosition = lookAt - length * forward;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
    }
}
